package controller;

import dao.ArticleDao;
import entity.Article;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/article/detail")
public class ArticleDetailServlet extends HttpServlet {
    ArticleDao articleDao = new ArticleDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //根据文章id调用dao层查询文章的方法将文章获取，放在请求作用域中传递jsp
        String id = request.getParameter("id");
        Article a = articleDao.getArticleById(id);
        //将文章放在附加属性作用域
        request.setAttribute("a",a);
        //获取评论
        request.setAttribute("id",id);
        int total = articleDao.lookTotal(id);
        //请求转发跳转文章详情的jsp页面
        request.getRequestDispatcher("/detail.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
